<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>地域管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/font.css">
    <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/xadmin.css">
    <link rel="stylesheet" href="/oauthplatform/static/lib/zTree/css/zTreeStyle/zTreeStyle.css">
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a>首页</a>
                <a><cite>学校管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>

<div class="layui-fluid layui-row layui-col-space15">
    <div class="layui-col-sm12 layui-col-md3">
        <div class="layui-card">
            <div class="layui-card-header">地域树</div>
            <div class="layui-card-body">
                <div id="treeDiv" class="ztree"></div>
            </div>
        </div>
    </div>


    <div class="layui-col-sm12 layui-col-md9">
        <div class="layui-card">
            <div class="layui-card-header">详细信息</div>
            <div class="layui-card-body ">
                <form class="layui-form layui-col-space5" id="searchForm">
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="schoolName" id="schoolName" placeholder="请输入学校名称"
                               class="layui-input">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <select name="type" id="type">
                            <option value="">办学类型</option>
                            <option value="公办">公办</option>
                            <option value="民办">民办</option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <select name="layer" id="layer">
                            <option value="">层次</option>
                            <option value="中职">中职</option>
                            <option value="高职(专科)">高职(专科)</option>
                            <option value="职业本科">职业本科</option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" type="button" onclick="reloadTable()" title="搜索">
                            <i class="layui-icon">&#xe615;</i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm" title="添加" onclick="addSchool()">
                            <i class="layui-icon">&#xe654;</i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm" title="批量导入" onclick="upload()">
                            <i class="layui-icon">&#xe67c;</i>
                        </button>
                    </div>
                </form>
            </div>

            <div class="layui-card-body">
                <div id="dataTables"></div>
            </div>
        </div>
    </div>

</div>
</body>
<script type="text/javascript" src="/oauthplatform/static/lib/jquery/jquery.3.4.1.js"></script>
<script src="/oauthplatform/static/lib/layui/layui.js" charset="utf-8"></script>
<script src="/oauthplatform/static/lib/other/html5.min.js"></script>
<script src="/oauthplatform/static/lib/other/respond.min.js"></script>
<script src="/oauthplatform/static/lib/zTree/js/jquery.ztree.core.js"></script>
<script src="/oauthplatform/static/lib/x-admin/xadmin.js"></script>
<script type="application/javascript">

    $(function () {
        loadTree();
    })

    var treeObj;

    function loadTree() {
        var setting = {
            async: {
                enable: true,
                url: '/oauthplatform/area/tree',
                type: "post"
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pid"
                }
            },
            callback: {
                beforeClick: function (treeId, treeNode, clickFlag) {
                    //设置节点点击事件以此加载右侧表格数据
                    reloadTable(treeNode.id);
                }
            }
        };
        treeObj = $.fn.zTree.init($("#treeDiv"), setting);
    }


    function reloadTable(pid) {
        table.reload('dataTables', {
            where: {name: $("#name").val(), isValid: $("#isValid").val(), pid: pid}
        });
    }


    var table;
    layui.use('table', function () {




        table = layui.table;
        //第一个实例
        table.render({
            elem: '#dataTables'
            , url: '/oauthplatform/school/list' //数据接口
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.records //解析数据列表
                };
            }
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外,如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next'] //自定义分页布局
                , first: false //不显示首页
                , last: false //不显示尾页
                , groups: 5
            }
            , cols: [[ //表头
                 {field: 'schoolName', title: '学校名称',width:200}
                , {field: 'type', title: '办学类型',width:100}
                , {field: 'layer', title: '层次',width:100}
                , {field: 'departmentName', title: '主管部门',width:150}
                , {
                    field: 'isValid', title: '操作', width:300,templet: function (d) {
                        var majorOrFaculty = ""; //TODO 将层级写入如果层次为中职就是专业设置 四个选项 为高职(专科)或职业本科 是院系管理加专业设置五个选项
                        // 应该
                        var buttonHtml = '';
                        if (d.layer == "中职") {
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="详情" onclick="showDetail(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe60a;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="部门管理" onclick="editUser(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe613;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="专业设置" onclick="deleteSchools(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe620;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="删除" onclick="deleteSchool(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe640;</i></button>';
                        } else {
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="详情" onclick="showDetail(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe60a;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="部门管理" onclick="editUser(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe613;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="院系管理" onclick="editUser(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe630;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="专业设置" onclick="deleteSchools(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe620;</i></button>';
                            buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="删除" onclick="deleteSchool(' + d.id + ')">' +
                                '<i class="layui-icon">&#xe640;</i></button>';
                        }
                        return buttonHtml;
                    }
                }
            ]]
        });
    });

    //搜索
    function reloadTable() {
        table.reload('dataTables', {
            where: {schoolName: $("#schoolName").val(), type: $("#type").val(), layer: $("#layer").val()}
        });
    }

    function showDetail(id) {
        if (id == null || id == '') {
            layer.msg("参数异常,请联系管理员");
            return false;
        }
        xadmin.open('详细信息', '/oauthplatform/user/detail?id=' + id, '', '', true);
    }

    function addSchool(){ xadmin.open('添加角色', '/oauthplatform/school/add', 800, 700, false); }

    function editUser(id) {
        if (id == null || id == '') {
            layer.msg("参数异常,请联系管理员");
            return false;
        }
        xadmin.open('修改用户', '/oauthplatform/user/edit?id=' + id, '', '', true);
    }
    function upload(){
         xadmin.open('批量导入', '/oauthplatform/school/upload', 600, 550, false);
    }
    function deleteSchool(id) {
        if (id == null || id == '') {
            layer.msg("参数异常,请联系管理员");
            return false;
        }
        layer.confirm('是否确认删除?', {
                btn: ['确认'] //可以无限个按钮
            },function(index, layero){
            $.ajax({
                type: "GET",//方法类型
                url: "/oauthplatform/school/delete/"+id,//url
                success: function (result) {
                    layer.msg(result.msg);
                    if (parseInt(result.code) == 200) {
                        setTimeout(function () {
                            location.reload();
                        }, 800);
                    }
                },
                error: function (result) {
                    layer.msg("系统异常,请联系管理员");
                }
            });
        })

    }

    function authorization(id) {
        if (id == null || id == '') {
            layer.msg("参数异常,请联系管理员");
            return false;
        }
        xadmin.open('授权', '/oauthplatform/awarded/index?id=' + id, 600, 750, false);
    }

</script>
</html>
